package com.java.imauoj.controler;

import com.java.imauoj.moudel.Login;
import com.java.imauoj.moudel.ResultVo;
import com.java.imauoj.moudel.Role;
import com.java.imauoj.moudel.User;
import com.java.imauoj.sercive.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.xml.transform.Result;

@RestController
@RequestMapping("api/v1")
public class LoginControler {

    @Autowired
    private LoginService loginService;

    //登陆
    @PostMapping(value = "login")
    public ResultVo login(@RequestBody User user, HttpSession session){
        System.out.println(user);
        ResultVo re = loginService.getUser(user.getUsername(),user.getPassword(),session);
        return re;
    }

    //获取登陆状态
    @GetMapping(value = "getLoginInfo")
    public ResultVo getLoginInfo(HttpSession session){
        ResultVo re = new ResultVo();
        Login login = new Login();
        User user = (User)session.getAttribute("login");
        Role role = (Role)session.getAttribute("role");
        login.setLogin(user);
        login.setRole(role);
        if(user!=null){
            re.setStatusCode(1);
            re.setMessage("已登陆");
            re.setData(login);
        }else{
            re.setStatusCode(0);
            re.setMessage("未登陆");
        }
        return re;
    }

    //获取系统信息
    @GetMapping(value = "getSystemInfo")
    public ResultVo getSystemInfo(){
        ResultVo re = new ResultVo();
        return re;
    }

}
